package game.adm.struts.action;

import java.util.List;

import game.adm.controller.WithdrawController;
import game.adm.dao.dto.WithdrawDTO;
import game.adm.struts.form.WithdrawForm;
import game.web.base.Constants;
import game.web.base.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import projectx.web.base.ConstantsProjectX;
import projectx.web.base.ProjectXSecurityAction;
import projectx.web.base.ProjectXForm;
import projectx.web.base.UserContext;
import projectx.web.base.navi.Function;

public class WithdrawAction extends ProjectXSecurityAction {

	@Override
	protected boolean isPostMethodOnly() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	protected ActionForward execute(User user, Function function,
			ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		UserContext uc = getUc();
		WithdrawForm withdrawForm = (WithdrawForm) form;
		String operator = withdrawForm.getOperator();
		uc.put(Constants.ADM_REQUEST_IP, request.getRemoteAddr());
		
		WithdrawController.execute(uc, (ProjectXForm) form);

		if("2".equals(operator)){
			WithdrawDTO dto = (WithdrawDTO) getUcAttribute(Constants.ADM_WITHDRAW_RECORD);
			request.setAttribute(ConstantsProjectX.VIEW_HELPER, dto);
		}else if("1".equals(operator)){
			List<WithdrawDTO> rows = (List<WithdrawDTO>) getUcAttribute(Constants.ADM_WITHDRAW_LIST);
			request.setAttribute(ConstantsProjectX.VIEW_HELPER, rows);
		}
		
		debugEnd();
		return findForward(mapping, forwardSuccess);
	}
}
